#include <GL/freeglut.h>
#include <cstdlib>
#include <cmath>

GLfloat cx = 0;
GLfloat cy = 0;
GLfloat length = 0.5f;
GLfloat theta = 0;

void display()
{
    glClearColor(0.8, 0.8, 0.8, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1, 0, 0);
    glLoadIdentity();
    glRotated(theta, 0, 0, 1);
    glRectf(cx - length / 2, cy - length / 2, cx + length / 2, cy + length / 2);
    glutSwapBuffers();
}

void idle()
{
    theta += 0.5f;
    if (theta >= 360)
        theta = 0;
    glutPostRedisplay();
}


void main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(400, 400);
    glutCreateWindow("旋转正方形");

   
    glutDisplayFunc(display);
    glutIdleFunc(idle);

    glutMainLoop();
}
